/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.control.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.bizz.risk.control.dto.RiskMeasureTaskRecordExcelDTO;
import com.hopes.bizz.risk.control.entity.RiskMeasureTaskRecordEntity;
import com.hopes.bizz.risk.control.mapper.RiskMeasureTaskRecordMapper;
import com.hopes.bizz.risk.control.service.RiskMeasureTaskRecordService;
import com.hopes.bizz.risk.control.vo.RiskMeasureTaskRecordExcelVO;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.common.entity.ValidateImportBO;
import com.hopes.boss.common.excel.vo.ErrorMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * 隐患排查任务
 *
 * @author cx
 * @date 2023-07-21 10:53:12
 */
@Service
public class RiskMeasureTaskRecordServiceImpl extends ServiceImpl<RiskMeasureTaskRecordMapper, RiskMeasureTaskRecordEntity> implements RiskMeasureTaskRecordService {

    @Override
    public ValidateImportBO<RiskMeasureTaskRecordExcelDTO> validateImport(List<RiskMeasureTaskRecordExcelDTO> excelDTOList) {
        ValidateImportBO<RiskMeasureTaskRecordExcelDTO> bo = new ValidateImportBO<>();
        List<ErrorMessage> errorMessageList = new ArrayList<>();
        List<RiskMeasureTaskRecordExcelDTO> saveList = new ArrayList<>(excelDTOList);
        int successNum = excelDTOList.size();
        int failedNum = 0;

        bo.setErrorMessages(errorMessageList);
        bo.setSaveList(saveList);
        bo.setSuccessNum(successNum);
        bo.setFailedNum(failedNum);
        return bo;
    }

    @Override
    public RiskMeasureTaskRecordEntity importDtoToEntity(RiskMeasureTaskRecordExcelDTO excelDto) {
        RiskMeasureTaskRecordEntity entity= new RiskMeasureTaskRecordEntity();
        BeanUtils.copyProperties(excelDto, entity);
        return entity;
    }

    @Override
    public RiskMeasureTaskRecordExcelVO exportEntityToVo(RiskMeasureTaskRecordEntity entity) {
        RiskMeasureTaskRecordExcelVO excelVO = new RiskMeasureTaskRecordExcelVO();
        BeanUtils.copyProperties(entity, excelVO);
        excelVO.setResponsibleUserIds(DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, entity.getResponsibleUserIds()));
        excelVO.setTaskHandleUserId(DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, entity.getTaskHandleUserId()));
        excelVO.setCheckStatus(DictResolver.getItemLabelByValue(RiskSysDictEnum.check_status, entity.getCheckStatus()));
        excelVO.setTaskStatus(DictResolver.getItemLabelByValue(RiskSysDictEnum.task_status, entity.getTaskStatus()));
        excelVO.setWorkType(DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_work_type, entity.getWorkType()));

        return excelVO;
    }

    @Override
    public Long countImeiLimitTime(Date startTime, Date endTime) {
        return this.baseMapper.countImeiLimitTime(startTime, endTime).getCount();
    }

}
